# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy import interpolate

from scipy import interpolate
import matplotlib.pyplot as plt
import numpy as np

def f(x):
    x_points = [0, 1, 2, 3, 4, 5]
    y_points = [0, 1, 4, 9, 16, 25]  # 实际函数关系式为：y=x^2

    xnew = np.linspace(min(x_points), max(x_points), 100)  # 新制作100个x值。(等差、list[]形式存储)

    tck = interpolate.splrep(x_points, y_points)
    ynew = interpolate.splev(xnew, tck)  # 通过拟合的曲线，计算每一个输入值。(100个结果，list[]形式存储)

    plt.scatter(x_points[:], y_points[:], 25, "red")  # 绘制散点
    plt.plot(xnew, ynew)  # 绘制拟合曲线图
    plt.show()
    return interpolate.splev(x, tck)

print(f(10))

data = pd.read_csv('./TX_ModOutSource.csv')
x = data['Freq']  # 取第一列数据
y = data['Pow']  # 取第二列数据
# 进行样条插值
tck = interpolate.splrep(x, y)
xx = np.linspace(min(x), max(x), 1000)
yy = interpolate.splev(xx, tck, der=0)
print(yy)
plt.plot(x, y, 'o', xx, yy)
plt.show()
print(interpolate.splev(450, tck))
